home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / dehqx-20 / mysystem.uni < prev    next >
Text File  |  1991-08-23  |  3KB  |  141 lines

  1. unit MySystem7;
  2. { DeHQX v2.0.0 ⌐ Peter Lewis, Aug 1991 }
  3.  
  4. interface
  5.  
  6.     uses
  7.         Types, OSUtils, Files, AppleTalk, Aliases, PPCToolBox, Processes, EPPC, Notification, AppleEvents, MyUtilities, MyNotifier, Folders;
  8. {Note:  InitUtilities must be called prior to using functions in this file }
  9. {            (It is normally called by InitMainLoop in MyMainLoop.unit) }
  10.  
  11.     function MyResolveAliasFile (var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
  12.     function MyFindFolder (vrn: INTEGER; folder: OSType; var ovrn: INTEGER; var oDirID: LONGINT): OSErr;
  13.     function MyInteractWithUser (idleproc: Ptr): OSErr;
  14.     function MyGetAPPL (sig: OSType; var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
  15.  
  16. implementation
  17.  
  18.     const
  19.         pref_folder = 'Preferences';
  20.  
  21.     function MyResolveAliasFile (var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
  22.         var
  23.             fs: FSSpec;
  24.             isfolder, wasalias: boolean;
  25.             oe: OSErr;
  26.     begin
  27.         if system7 then begin
  28.             with fs do begin
  29.                 vRefNum := vrn;
  30.                 parID := dirID;
  31.                 name := fname;
  32.                 oe := ResolveAliasFile(fs, true, isfolder, wasalias);
  33.                 if oe = noErr then begin
  34.                     vrn := vRefNum;
  35.                     dirID := parID;
  36.                     fname := name;
  37.                 end;
  38.             end;
  39.         end
  40.         else
  41.             oe := noErr;
  42.         MyResolveAliasFile := oe;
  43.     end;
  44.  
  45.     function MyFindFolder (vrn: INTEGER; folder: OSType; var ovrn: INTEGER; var oDirID: LONGINT): OSErr;
  46.         var
  47.             oe: OSErr;
  48.             name: str255;
  49.             prefDirID: longInt;
  50.             pb: HParamBlockRec;
  51.     begin
  52.         if system7 then begin
  53.             oe := FindFolder(vrn, folder, true, ovrn, oDirID);
  54.         end
  55.         else begin
  56.             oe := GetDirID(sysenv.sysVRefNum, ovrn, oDirID);
  57.             if (oe = noErr) and (folder = kPreferencesFolderType) then begin
  58.                 name := pref_folder;
  59.                 oe := DirCreate(ovrn, oDirID, name, prefDirID);
  60.                 if oe = noErr then
  61.                     oDirID := prefDirID
  62.                 else begin
  63.                     with pb do begin
  64.                         ioNamePtr := @name;
  65.                         ioVRefNum := ovrn;
  66.                         ioDirID := oDirID;
  67.                         ioFDirIndex := 0;
  68.                     end;
  69.                     oe := PBGetCatInfo(@pb, false);
  70.                     if oe = noErr then
  71.                         oDirID := pb.ioDirID;
  72.                 end;
  73.                 oe := noErr;
  74.             end;
  75.         end;
  76.         MyFindFolder := oe;
  77.     end;
  78.  
  79.     function MyInteractWithUser (idleproc: Ptr): OSErr;
  80.         var
  81.             oe: OSErr;
  82.     begin
  83.         if system7 then
  84.             oe := AEInteractWithUser(maxLongInt, nil, idleproc)
  85.         else begin
  86.             if in_foreground then
  87.                 MyInteractWithUser := noErr
  88.             else begin
  89.                 Notify(true, true, 128, 0, 0, 0);
  90. { Should wait til we are in the foreground, but its too messy }
  91.             end;
  92.         end;
  93.     end;
  94.  
  95.     function MyGetAPPL (sig: OSType; var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
  96.         var
  97.             i: integer;
  98.             pbdt: DTPBRec;
  99.             crdate: longInt;
  100.             oe: OSErr;
  101.             found: boolean;
  102.     begin
  103.         found := false;
  104.         if system7 then begin
  105.             i := 1;
  106.             repeat
  107.                 vrn := 0;
  108.                 oe := GetVolInfo(fname, vrn, i, crdate);
  109.                 i := i + 1;
  110.                 if oe = noErr then begin
  111.                     with pbdt do begin
  112.                         fname := '';
  113.                         ioNamePtr := @fname;
  114.                         ioVRefNum := vrn;
  115.                         oe := PBDTGetPath(@pbdt);
  116.                         if oe = noErr then begin
  117.                             ioIndex := 0;
  118.                             ioFileCreator := sig;
  119.                             oe := PBDTGetAPPLSync(@pbdt);
  120.                             if oe = noErr then
  121.                                 found := true;
  122.                         end;
  123.                     end;
  124.                     oe := noErr;
  125.                 end;
  126.             until found or (oe <> noErr);
  127.         end;
  128.         if found then begin
  129.             oe := noErr;
  130.             dirID := pbdt.ioAPPLParID;
  131.         end
  132.         else begin
  133.             oe := afpItemNotFound;
  134.             vrn := 0;
  135.             dirID := 2;
  136.             fname := '';
  137.         end;
  138.         MyGetAPPL := oe;
  139.     end;
  140.  
  141. end.